package com.example.boos.orderDetail;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.example.boos.R;
import com.example.boos.context.BossInfo;
import com.example.boos.pojo.Orders;

public class OrderDetailActivity extends AppCompatActivity {

    private Orders order; // 订单详情
    private TextView userAddr;
    private TextView userInfo;
    private TextView storeAddr;
    private TextView storeInfo;
    private TextView De_StoreName;
    private MyListViewForScrollView orderFoods;
    private TextView De_deliveryFee;
    private TextView De_orderPrice;
    private TextView De_remark;
    private TextView BottomOrderPrice;
    private Button De_back;



    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_order_detail);
        initData();
        initView();
    }

    private void initData(){
        Bundle extras = getIntent().getExtras();
        order = (Orders) extras.getSerializable("order");
        System.out.println(order);
    }

    private void initView(){
          userAddr = findViewById(R.id.userAddr);
          userInfo= findViewById(R.id.userInfo);
          storeAddr= findViewById(R.id.storeAddr);
          storeInfo= findViewById(R.id.storeInfo);
          De_StoreName= findViewById(R.id.De_storeName);
          orderFoods= findViewById(R.id.orderFoods);
          De_deliveryFee= findViewById(R.id.De_deliveryFee);
          De_orderPrice= findViewById(R.id.De_orderPrice);
          De_remark= findViewById(R.id.De_remark);
          BottomOrderPrice= findViewById(R.id.BottomOrderPrice);
          De_back= findViewById(R.id.De_back);
          // 设置参数
        userAddr.setText(order.getUserAddress().getAddress());
        userInfo.setText(order.getUserAddress().getReceiveName()+" "+order.getUserAddress().getTelephone());
        storeAddr.setText(BossInfo.currentStoreAddress.getAddress());
        storeInfo.setText(BossInfo.currentStoreAddress.getBottome());
        De_StoreName.setText(BossInfo.currentStore.getStoreName());
        De_deliveryFee.setText(String.valueOf(order.getDeliveryFee()));
        De_orderPrice.setText(String.valueOf(order.getTotalPrice()));
        De_remark.setText(order.getRemark());
        BottomOrderPrice.setText(String.valueOf(order.getTotalPrice()));

        // =================================================
        OrderDetailAdapter adapter = new OrderDetailAdapter(order.get_foodList(),this);
        orderFoods.setAdapter(adapter);

        // 设置监听器
        De_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                /*Intent intent = new Intent();
                intent.setComponent(new ComponentName(OrderDetailActivity.this, MainActivity.class));
                OrderDetailActivity.this.startActivity(intent);*/
                finish();
            }
        });
    }
}